<%--
    Document   : viewDairy
    Created on : 2011-5-18, 22:55:23
    Author     : tecton
--%>

<%@page import="com.dairy.structures.Company"%>
<%@page import="com.dairy.structures.Dairyproduct"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%
    Company[] company = (Company[]) request.getAttribute("company");
    String[] category = (String[]) request.getAttribute("category");
    String companyName = "<option value=\"-1\" selected>all</option>";
    for (int i = 0; i < company.length; ++i)
        companyName += "<option value=\"" + company[i].id_company + "\">" + company[i].name + "</option>";
    String categoryName = "<option value=\"null\" selected>all</option>";
    for (int i = 0; i < category.length; ++i)
        categoryName += "<option value=\"" + category[i] + "\">" + category[i] + "</option>";

%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript">
        function submit(){
            var id_company = document.getElementById('company');
            var name_category = document.getElementById('category');
            var selectedCompany = id_company.options[id_company.selectedIndex].value;
            var selectedCategory = name_category.options[name_category.selectedIndex].value;
            window.location = "./viewProduct.do?id_company=" + selectedCompany + "&name_category=" + selectedCategory;
        }
        function submitItem(name, product){
            var cName = document.getElementById(name);
            var pName = document.getElementById(product);
            window.location = "./modifyOrders.do?name_company=" + cName.innerHTML + "&name_product=" + pName.innerHTML;
        }
    </script>
    <title>订奶系统</title>
    <link rel="stylesheet" type="text/css" href="./home_style.css"/>
</head>

<body>
    <div class="wrapper">
        <div class="header">
            <h1>User Home Page</h1>
        </div>

        <div class="content">

            <div class="primary">
                <select name="company" id="company">
                    <%= companyName%>
                </select>
                <select name="category" id="category">
                    <%= categoryName%>
                </select>
                <button name="modify" onclick="javascript:submit()">OK</button>

                <%
                    Dairyproduct[] product = (Dairyproduct[])request.getAttribute("product");
                    if (product != null){
                %>
                <table border="1">
                    <tr>
                        <th>company</th>
                        <th>product name</th>
                        <th>category</th>
                        <th>property</th>
                        <th>price</th>
                        <th>to do</th>
                    </tr>
                    <% for (int i = 0; i < product.length; ++i){%>
                    <tr>
                    <td id ="<%="company" + i%>"><%=product[i].company%></td>
                    <td id ="<%="product" + i%>"><%=product[i].name%></td>
                    <td><%=product[i].category%></td>
                    <td><%=product[i].property%></td>
                    <td><%=product[i].price%></td>
                    <td><button onclick="javascript:submitItem('<%="company" + i%>', '<%="product" + i%>');">Order</button></td>
                    </tr>
                    <%}%>
                </table>
                <%}%>
            </div>

            <div class="secondary">
                <ul class="nav">
                    <li class="first"><a href="user/index.do">Home</a></li>
                    <li><a href="./logout.do">logout</a></li>
                    <li><a href="./modifyPersonInfo.do">modify information</a></li>
                    <li><a href="./modifyOrders.do">orders</a></li>
                    <li><a href="./viewProduct.do">view product</a></li>
                </ul>
            </div>

        </div>

        <div class="footer">
            <p>Dairy Product Ordering System - All Rights Reserved</p>
        </div>
    </div>
</body>
</html>